package kr.saeildamil.androidstudy.ch19;

import kr.saeildamil.androidstudy.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class ThreadTest extends Activity {
	int mMainValue;
	int mBackValue;

	TextView mMain;
	TextView mBack;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.threadtest);

		mMain = (TextView) findViewById(R.id.ch19_threadtest_mainvalue);
		mBack = (TextView) findViewById(R.id.ch19_threadtest_backvalue);

		BackThread thread = new BackThread();
		thread.setDaemon(true);
		thread.start();
	}// end of method oncreate()

	public void mOnClick(View v) {
		mMainValue++;
		mMain.setText("Main Value : " + mMainValue);
		mBack.setText("Back Value : " + mBackValue);
	}// end of method mOnclick

	class BackThread extends Thread {
		@Override
		public void run() {
			super.run();
			while (true) {
				mBackValue++;
				try {
					Thread.sleep(1000);
					// mBack.setText("Back Value : " + mBackValue);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}// end of class BackThread
}
